using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.ModelConfiguration;
using Leo.Entities;

namespace Leo.Repository.Mapping
{
    public class EmpleadoMap : EntityTypeConfiguration<Empleado>
    {
        public EmpleadoMap()
        {
            // Primary Key
            this.HasKey(t => t.Id);

            // Properties
            this.Property(t => t.DNI)
                .IsRequired()
                .HasMaxLength(8);

            this.Property(t => t.Nombres)
                .IsRequired()
                .HasMaxLength(50);

            this.Property(t => t.Apellidos)
                .IsRequired()
                .HasMaxLength(100);

            this.Property(t => t.Telefono)
                .HasMaxLength(10);

            this.Property(t => t.UserName)
                .IsRequired()
                .HasMaxLength(20);

            this.Property(t => t.Password)
                .IsRequired()
                .HasMaxLength(20);

            // Table & Column Mappings
            this.ToTable("Empleado");
            this.Property(t => t.Id).HasColumnName("Id");
            this.Property(t => t.DNI).HasColumnName("DNI");
            this.Property(t => t.Nombres).HasColumnName("Nombres");
            this.Property(t => t.Apellidos).HasColumnName("Apellidos");
            this.Property(t => t.Telefono).HasColumnName("Telefono");
            this.Property(t => t.UserName).HasColumnName("UserName");
            this.Property(t => t.Password).HasColumnName("Password");
            this.Property(t => t.IdRol).HasColumnName("IdRol");

            // Relationships
            this.HasRequired(t => t.Rol)
                .WithMany(t => t.Empleadoes)
                .HasForeignKey(d => d.IdRol);

        }
    }
}
